<?php

namespace app\common\model\Order;

use think\Model;

class Order extends Model
{
    // 数据表
    protected $table = 'pre_order';

    // 开启自动写入时间
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;

    // 追加字段
    protected $append = [
        'status_text',
        'createtime_text'
    ];

    public function getStatusTextAttr($value, $data)
    {
        $list = [0 => '未支付', 1 => '已支付', 2 => '已发货', 3 => '已收货', 4 => '已评价', -1 => '已退货', -2 => '退货中', -3 => '拒绝退货'];

        return $list[$data['status']];
    }

    public function getCreatetimeTextAttr($value, $data)
    {
        return date('Y-m-d H:i:s', $data['createtime']);
    }
}
